package com.hs.sfzy.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hs.sfzy.entity.Course;
import com.hs.sfzy.entity.CourseQuery;
import com.hs.sfzy.mapper.CourseMapper;
import com.hs.sfzy.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName CourseServiceImpl
 * @Description TODO
 * @Author Chen
 * @Date 2025年08月12日 21:04
 * @Version 1.0
 */
@Service
public class CourseServiceImpl implements CourseService {
    @Autowired
    private CourseMapper courseMapper;

    @Override
    public PageInfo<Course> getCourseList(Course course, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Course> courseList = courseMapper.getCourseList(course);
        PageInfo<Course> pageInfo = new PageInfo<Course>(courseList);
        return pageInfo;
    }

    @Override
    public Course getCourseByCourseId(Integer id) {
        return courseMapper.getCourseByCourseId(id);
    }

    @Override
    public PageInfo<Course> getCourseByzxsId(Integer id, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Course> courseList = courseMapper.getCourseByzxsId(id);
        PageInfo<Course> pageInfo = new PageInfo<>(courseList);
        return pageInfo;
    }

    @Override
    public PageInfo<Course> selectCourseBySort(String sortType, String interval, int pageNum, int pageSize) {

        PageHelper.startPage(pageNum, pageSize);
        CourseQuery courseQuery = new CourseQuery();
        String priceInterval[];
        System.out.println(interval);
        Double minPrice=null;
        Double maxPrice=null;
        if(sortType!=null&&!sortType.isEmpty()&&!"null".equals(sortType)){
            courseQuery.setSortType(sortType);
        }
        if(interval!=null&&!interval.isEmpty()&&!"null".equals(interval)){
            priceInterval = interval.split("-");
            minPrice=Double.valueOf(priceInterval[0]);
            maxPrice=Double.valueOf(priceInterval[1]);
            courseQuery.setMinPrice(minPrice);
            courseQuery.setMaxPrice(maxPrice);

            System.out.println(minPrice+" "+maxPrice+"5555");
        }



        List<Course> courses = courseMapper.selectCourseBySort(courseQuery);
        PageInfo<Course> pageInfo = new PageInfo<>(courses);
        return pageInfo;
    }
}
